# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-dromozoa-utf8
_pkgname=dromozoa-utf8
pkgver=1.17
pkgrel=0
pkgdesc="Lua 5.3 compatible pure-Lua UTF-8 implementation"
url="https://github.com/dromozoa/dromozoa-utf8/"
arch="noarch"
license="GPL-3.0-or-later"
checkdepends="luajit"
source="$pkgname-$pkgver.tar.gz::https://github.com/dromozoa/$_pkgname/archive/v$pkgver.tar.gz
	test.sh.patch"
builddir="$srcdir/$_pkgname-$pkgver"

_luaversions="5.1 5.2 5.3"
for _v in $_luaversions; do
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
	checkdepends="$checkdepends lua$_v"
done

check() {
	local out
	local jit
	[ "$CARCH" != "s390x" ] && jit="jit"
	local lver; for lver in $_luaversions $jit; do
		msg "Testing on lua$lver"
		./test.sh lua$lver
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local lmod_dir="$subpkgdir/usr/share/lua/$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_pkgname/$pkgver-1"

	cd "$builddir"
	mkdir -p "$lmod_dir"
	cp -r dromozoa "$lmod_dir"/

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="
3134dcf0b84fcbd587fb978bb518a10e7fb4de23707a5fc2fb1f4922d77f26d066ce4c77a6635574d8ed46786955f28f590a16cb81d72aaddc605a5b25301a36  lua-dromozoa-utf8-1.17.tar.gz
5b24a1aef26a934aea9e116af857a0323d5e0b639f2d5ff66b6cc5310bf9c2315855f3034e3c5e40bda0e91f970ba90ebdd97c6eb08b2f6683b131fe5ba2ecb5  test.sh.patch
"
